/*
 * WallObject.java
 *
 * Created on June 18, 2008, 10:32 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package levelbuilder;

import java.awt.*;
import javax.swing.*;

import java.awt.geom.AffineTransform;
import java.awt.image.*;
/**
 *
 * @author ew562c
 */
public class WallObject extends JPanel{
    Image image;
    double rotation;
    int x;
    int y;
    double zoom;
    boolean selected = false;
    /** Creates a new instance of WallObject */
    public WallObject(Image img) {
        this.image = img;
        this.x = 0;
        this.y = 0;
        this.rotation = 0;
        this.zoom = 1;
    }
    
    public void Reset()
    {
        this.rotation = 0;
        this.zoom = 1;
    }
    
    public void SetImage(Image img){this.image = img;}
    
    public void SetPosition(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
    
    public void SetRotation(double ang)
    {
        this.rotation = ang;   
    }
    
    public void SetZoom(double zoom)
    {
        this.zoom = zoom;   
    }
    
    public boolean IsSelected(){return this.selected;}
    
    public int GetObjHeight(){return (int)(image.getHeight(this) * this.zoom);}
    
    public int GetObjWidth(){return (int)(image.getWidth(this) * this.zoom);}
    
    public int GetWidth(){return (int)(image.getWidth(this));}
    public int GetHeight(){return (int)(image.getHeight(this));}
    
    public boolean Select(int x, int y)
    {
        if(x > this.x && x < this.x + image.getWidth(this)*this.zoom)
        {
            if(y > this.y && y < this.y + image.getHeight(this)*this.zoom)
            {
                this.selected = true;
                return true;
            }
        }
        this.selected = false;
        return false;
    }
    
    
    public int GetOffsetX(){return this.x;}
    
    public int GetOffsetY(){return this.y;}
    
    public int GetX(){return this.x;}
    
    public int GetY(){return this.y;}
    
    public double GetRotation(){return this.rotation;}
    
    public double GetZoom(){return this.zoom;}

    public Image GetImage()
    {
        BufferedImage bi = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB);
        
        Graphics2D g = (Graphics2D)bi.getGraphics();
        g.drawImage(image,0, 0,null);
       // g.setClip(0,0,640,480);
        AffineTransform at = new AffineTransform();
        at.scale(this.zoom, this.zoom);
        
        
        
        at.rotate(Math.toRadians(this.rotation), image.getWidth(this)/2, image.getHeight(this)/2);
        
        BufferedImageOp bio;
    
      //  AffineTransform translationTransform;
      //  translationTransform = findTranslation(at, bi);
      //  at.preConcatenate(translationTransform);
    
        bio = new AffineTransformOp(at,AffineTransformOp.TYPE_BILINEAR);
        BufferedImage dbio = bio.filter(bi, null);
        
        return dbio;
    }
}
 